<%@ page language="java" import="java.util.*" pageEncoding="utf-8"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
<!doctype html>
<html class="no-js">
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<title>管理首页</title>
<meta name="description" content="这是一个 首页面">
<meta name="keywords" content="index">
<meta name="viewport"
	content="width=device-width, initial-scale=1, maximum-scale=1, user-scalable=no">
<meta name="renderer" content="webkit">
<meta http-equiv="Cache-Control" content="no-siteapp" />
<meta name="apple-mobile-web-app-title" content="Amaze UI" />
<style>
.admin-main { 
	background: #fff;
}
.table-bordered {
  border:none
}
.am-selected {
  width: 100% !important;
  border-radius: 4px !important;
  border: 1px solid #999 !important; 
}
.am-selected-btn {
    width: 100%;
	border:0 !important;
}
.wddd-list-jtzl{
	/* padding: 5px 0 0!important; */
	padding-top:5px;
	text-align:center;
}
.wddd-list-jtzl > ul > li{
	float:left;
	cursor:pointer;
}
.timetcc{
	width:411px!important;
}
</style>
<jsp:include page="../inc.jsp"></jsp:include>
</head>

<body>
  <!-- content start -->
  <div class="admin-content">
	
    <div class="am-cf am-padding">
      <div class="am-fl am-cf"><strong class="am-text-primary am-text-lg">账号管理</strong></div>
    </div>
	<div class="am-g" style="padding:15px 0;background:#fff;border-top:1px solid #ccc;border-bottom:1px solid #ccc;"  data-am-sticky="{top:51,animation: 'slide-top'}">
       <div class="am-u-sm-12 am-u-md-12" >
      	<div>
      			<form id="form-search" onsubmit="return false;">
      				账号：<input  style="font-size : 14px; margin-right:20px;" type="text" name="loginName" id="form_loginName"> 
      				姓名：<input   style="font-size : 14px; margin-right:20px;" type="text" name="personName" id="form_personName"> 
      				
      				<!-- 类型：<select style="font-size : 14px; width: 150px; padding: 2px 0;"  id="select_type_">
      						<option value="">请选择</option>
     						<option value="1">等级1</option>
     						<option value="2">等级2</option>
     						<option value="3">等级3</option>
     						<option value="4">等级4</option>
     						<option value="5">等级5</option>
     						<option value="6">等级6</option> 
      				<input type="hidden" name="type" id="form_type"> -->
      				<span style="font-size:16px">注册/关注时间：</span>
		            <div class="timediv">
		                <input type="text" placeholder="" readonly name="startDate" id="starttime" onClick="timeshow()"> -
		                <input type="text" placeholder="" readonly name="endDate" style="margin-right:22px" id="endtime" onClick="timeshow()">
		                <i class="am-icon-calendar" onClick="timeshow()"></i>
		            </div>
      				<br/>
	            	<div style="margin-top: 8px;">
	            		手机号码：<input  style="font-size : 14px;margin-right:20px;" type="text" name="phone" id="form_phone"> 
	            		余额：<input  style="font-size : 14px;width:110px;" type="text" name="minMoney" id="minMoney">—<input  style="font-size : 14px;width:110px;margin-right:20px; " type="text" name="maxMoney" id="maxMoney">
	            		积分：<input  style="font-size : 14px;width:110px; " type="text" name="minIntegral" id="minIntegral">—<input  style="font-size : 14px;width:110px; " type="text" name="maxIntegral" id="maxIntegral">	
	            	</div>
		            <button class="am-btn am-btn-primary am-btn-xs"  style="margin-right:5px; margin-left: 20px;margin-top: 8px"onclick="query();"><i class="fa fa-search"></i>查询</button>
	      			<button class="am-btn am-btn-primary am-btn-xs" style="margin-top: 8px;" onclick="queryAll();"><i class="fa fa-search"></i>清空</button>
      			</form>
      			
      		</div>
      </div>
	</div>
    <div class="am-g" style="padding:15px 0;border-bottom:1px solid #ccc;">
      <div class="am-u-sm-12 am-u-md-6">
        <div class="am-btn-toolbar">
<!--             <div class="am-btn-group"><button type="button" onclick="add()" class="am-btn am-btn-xs am-btn-primary am-radius" data-am-modal="{target: '#doc-modal-1', closeViaDimmer: false, width: 800, height: 400}"><span class="am-icon-plus"></span>添加</button></div> -->
            <div class="am-btn-group"><button type="button" onclick="removeAll()" class="am-btn am-btn-xs am-btn-primary am-radius" ></span>批量删除</button></div>
            <div class="am-btn-group"><button type="button" onclick="user_excel()" class="am-btn am-btn-xs am-btn-primary am-radius" ></span>商城Excel导出</button></div>
        </div>
        <!--新增弹出 start-->
             <div class="am-modal am-modal-no-btn" tabindex="-1" id="doc-modal-1" style="top:42%">
                <div class="admin-content">
                    <div class="am-cf am-padding">
                      <div class="am-fl am-cf"><strong id="operation" class="am-text-primary am-text-lg"></strong></div>
                    </div>
                  <form id="form" name="form" >
                  <input type="hidden" id="form_type_1">
                    <div class="am-tabs am-margin" id="form_remove">
                          <div class="am-u-sm-12 djzjsxtc">
                              <div class="am-u-sm-4 am-text-center">
                              	登录账号：
                              </div>
                              <div class="am-u-sm-8">
                                  <input readonly="value" type="text" id = "loginName" name = "puser.loginName">
                              </div>
                          </div>
<!--                           <input type="hidden" id="pwd" name="puser.pwd" value="111111"> -->
                          <div class="am-u-sm-12 djzjsxtc">
                               <div class="am-u-sm-4 am-text-center">
                              	姓名：
                              </div>
                              <div class="am-u-sm-8">
                                  <input type="text" id = "personName" name = "puser.personName">
                              </div>
                          </div>
                          <div class="am-u-sm-12 djzjsxtc">
                              <div class="am-u-sm-4 am-text-center">
                          	     账号类别：
                              </div>
                              <div class="am-u-sm-8">
                             	 <select style="width: 100%; border-radius: 4px;border: 1px solid #999; padding: 5px;"  id="select_type" >
                             	 <option>无</option>
     						</select>
                                  <input type="hidden" id = "type" name = "puser.type">
                              </div>
                              <input type="hidden"  id="user_id" name="puser.id">
                           </div>
                           <div class="am-u-sm-12 djzjsxtc">
                              <div class="am-u-sm-4 am-text-center">
                          	     是否锁定：
                              </div>
                              <div class="am-u-sm-8">
                             	 <select style="width: 100%; border-radius: 4px;border: 1px solid #999; padding: 5px;"  id="select_isLock" name="puser.isLock">
                                	<option value="0">不锁定</option>
		      						<option value="1">锁定</option>
		      						</select>
                              </div>
                           </div>
<!--                            <div class="am-u-sm-12 djzjsxtc"> -->
<!--                               <div class="am-u-sm-4 am-text-center"> -->
<!--                               	邮箱地址： -->
<!--                               </div> -->
<!--                               <div class="am-u-sm-8"> -->
<!--                                   <input type="text" datatype="e" id = "email" name = "puser.email" errormsg="请输入正确的邮箱地址！"> -->
<!--                               </div> -->
<!--                           </div> -->
<!--                           <div class="am-u-sm-12 djzjsxtc"> -->
<!--                               <div class="am-u-sm-4 am-text-center"> -->
<!--                   	  		联系电话： -->
<!--                               </div> -->
<!--                               <div class="am-u-sm-8"> -->
<!--                                   <input type="text" datatype="m" id="phone" name="puser.phone" errormsg="请输入正确的手机号码"></input> -->
<!--                               </div> -->
<!--                           </div> -->
                          
                          <div class="clear"></div>
                        <div class="clear"></div>
                    </div>
                  </form>
                    <div class="am-margin am-text-right">
                      <button id="btn_sub" type="button" class="am-btn am-btn-primary am-btn-xs"  >提交保存</button>
                      <button type="button" class="am-btn am-btn-primary am-btn-xs" data-am-modal-close>放弃保存</button>
                    </div>
                   
                </div>
            </div>
              <!--增加属性弹出 end-->
              
              <!-- 跳转查看详情开始 -->
              <div class="moadltcc" id="doc-modal-4" style="width:1000px;margin-left:-500px;">
            	<iframe name="rightFrame" id="rightFrame" width="1000" height="550" frameborder=0 scrolling=auto src=""></iframe>
            </div>
           
              <!-- 跳转查看详情结束-->
      </div>
    </div>

    <div class="am-u-sm-12">
          <div class="am-u-sm-12 am-u-md-12 am-u-lg-12 tablemenu">
				<div id="dtGridContainer_2_1_2" class="dt-grid-container"></div>
				<div id="dtGridToolBarContainer_2_1_2" class="dt-grid-toolbar-container"></div>
          </div>
    </div>
  </div>
  <!-- content end -->
</div>

<div class="am-modal am-modal-alert" tabindex="-1" id="my-alert">
  <div class="am-modal-dialog">
    <div class="am-modal-hd">提示</div>
    <div class="am-modal-bd">
      <span id="msg_alert">Hello world！</span>
    </div>
    <div class="am-modal-footer">
      <span class="am-modal-btn">确定</span>
    </div>
  </div>
</div>
<!-- 删除提示框 -->
<div class="am-modal am-modal-confirm" tabindex="-1" id="my-confirm">
  <div class="am-modal-dialog">
    <div class="am-modal-hd">提示</div>
    <div class="am-modal-bd">
      你确定要删除吗？
    </div>
    <div class="am-modal-footer">
    	<input type="hidden" id="del_id">
      <span class="am-modal-btn" data-am-modal-cancel>取消</span>
      <span class="am-modal-btn" data-am-modal-confirm onclick="doDel()">确定</span>
    </div>
  </div>
</div>

</body>
<script>
	
	var mainIdOfGoodsInfo;
	
	var dtGridColumns_2_1_2 = [
				{
								id :'loginName',
								title : '账号',
								columnClass:'text-center'
				}, 
				{
								id :'type',
								title : '用户类型',
								columnClass:'text-center',
								resolution : function(value, record,column, grid, dataNo, columnNo){
									var content = '';
									content +='微信用户';									
				    				return content;
								}
				}, 
				{
								id :'gradeName',
								title : '级别',
								columnClass:'text-center'
				}, 
				{
								id :'money',
								title : '余额',
								columnClass:'text-center'
				},
			    {
								id :'integral',
								title : '积分',
								columnClass:'text-center'
				},
				{
								id :'shopCouponsCount',
								title : '优惠券',
								columnClass:'text-center'
				},
				{
								id :'personName',
								title : '姓名',
								columnClass:'text-center'
				},
				{
								id :'phone',
								title : '电话',						
								columnClass:'text-center'
				},
				{
								id :'labelName',
								title : '标签',						
								columnClass:'text-center'
				},
				{
								id :'isLock',
								title : '是否锁定',
							columnClass:'text-center',
								resolution : function(value, record,column, grid, dataNo, columnNo){
									var content = '';
									if(value==0)
									{
									 content +='<font color="green">可用</font>';
									}else
									{
									 content += '<font color="red">锁定</font>';
									}
				    				return content;
								}
				}, 
				/* {
								id :'createTime',
								title : '创建时间',
								columnClass:'text-center'
				}, */
				{
					id:'id',
					title : '操作',
					columnClass:'text-center',
					resolution : function(value,record, column, grid, dataNo, columnNo){
// 						value：当前单元格的值  record：记录集，可以直接获取该行的数据 column：列对象 grid：表格对象  dataNo：数据编号，从0开始  columnNo：列编号，从0开始
						var content = '';
       					 content += '<button class="btnbtn-xs btn-default" onclick="doEdit(\''+record.id+'\');"><i class="fafa-edit"></i>  编辑</button>';
        				 content += '  ';
        			     content += '<button class="btn btn-xs btn-danger" onclick="del(\''+record.id+'\');"><i class="fa fa-trash-o"></i>  删除</button>';
						return 	content;
					}
				},
				{id:'userDetailHtml', title:'', type:'date', format:'yyyy-MM-dd hh:mm:ss', otype:'time_stamp_s', columnClass:'text-center',hideType:'lg|md|sm|xs',resolution:function(value, record, column, grid, dataNo, columnNo)
					{ 
						return 	 value;				
	           		} 
				}
		];
	var dtGridOption_2_1_2 = {
		lang : 'zh-cn',
		ajaxLoad : true,
		check:true,
		loadURL :  '${pageContext.request.contextPath}/user/showUserGrid.action',
		exportFileName : '用户列表',
		columns : dtGridColumns_2_1_2,
		gridContainer : 'dtGridContainer_2_1_2',
		toolbarContainer : 'dtGridToolBarContainer_2_1_2',
		tools : '',
		pageSize : 10,
		pageSizeLimit : [10, 20, 50]
	};
	
	//表格初始化
	/* var dtGridOption_2_1_9 = {
		lang : 'zh-cn',
		ajaxLoad : true,
// 		loadAll : true,  //如果是分页数据 ,此项不用写
		exportFileName : '用户列表',
		check:true,
		loadURL :  '${pageContext.request.contextPath}/user/showUserGrid.action',
		columns : [
				{
								id :'loginName',
								title : '账号',
								columnClass:'text-center'
				}, 
				{
								id :'type',
								title : '类型',
							columnClass:'text-center',
					resolution : function(value, record,column, grid, dataNo, columnNo){
						var content = '';
						if(value==1)
						{
						 content +='等级1';
						}else if(value==2)
						{
						 content += '等级2';
						}else if(value==3){
						content += '等级3';
						}else if(value==4){
						content += '等级4';
						}else if(value==5){
						content += '等级5';
						}else if(value==6){
						content += '等级6';
						}
	    				return content;
					}
				}, 
				{
								id :'money',
								title : '账号余额',
								columnClass:'text-center'
				},
			    {
								id :'integral',
								title : '积分',
								columnClass:'text-center'
				},
				{
								id :'personName',
								title : '真实姓名',
								columnClass:'text-center'
				},
				{
								id :'phone',
								title : '联系电话',						
								columnClass:'text-center'
				},
				{
								id :'isLock',
								title : '是否锁定',
							columnClass:'text-center',
								resolution : function(value, record,column, grid, dataNo, columnNo){
									var content = '';
									if(value==0)
									{
									 content +='<font color="green">可用</font>';
									}else
									{
									 content += '<font color="red">锁定</font>';
									}
				    				return content;
								}
				}, 
				{
								id :'createTime',
								title : '创建时间',
								columnClass:'text-center'
				},
				{
					id:'id',
					title : '操作',
					columnClass:'text-center',
					resolution : function(value,record, column, grid, dataNo, columnNo){
// 						value：当前单元格的值  record：记录集，可以直接获取该行的数据 column：列对象 grid：表格对象  dataNo：数据编号，从0开始  columnNo：列编号，从0开始
						var content = '';
       					 content += '<button class="btnbtn-xs btn-default" onclick="doEdit(\''+record.id+'\');"><i class="fafa-edit"></i>  编辑</button>';
        				 content += '  ';
        			     content += '<button class="btn btn-xs btn-danger" onclick="del(\''+record.id+'\');"><i class="fa fa-trash-o"></i>  删除</button>';
						return 	content;
					}
				}
				
			],
		gridContainer : 'dtGridContainer_2_1_9',
		toolbarContainer :'dtGridToolBarContainer_2_1_9',
		tools : 'refresh',//|faseQuery|advanceQuery|export[excel,csv,pdf,txt]|print
		pageSize : 10,
		pageSizeLimit : [10, 20, 50],
	}; */

	var grid_2_1_2 = $.fn.DtGrid.init(dtGridOption_2_1_2);
	
	
	$(function(){
		grid_2_1_2.load();
		 LoadLevel();
		
		$("#form").Validform({btnSubmit:"#btn_sub"});
		$("#btn_sub").click(function(){
			save();
		});
	});
//加载角色
function select1(){
$("#select_role").html("");
	$.ajax({
			type : "post",
			url : "${pageContext.request.contextPath}/user/showRole.action",
			success : function(msg) {
			var obj=$.parseJSON(msg);
			for ( var i = 0; i < obj.length; i++) {
			$("#select_role").append("<option value=" + obj[i].id + ">" + obj[i].text + "</option>");
			}
			}
		})
}
//新增账号		
function add(){
$("#operation").html("新增账号");
$("#form_type_1").val("0");
// $("#isShow").hide();
$(':input','#form').val(''); 
$("#select_type").prop("disabled", false);
}

//编辑账号
function doEdit(id){
$("#operation").html("编辑账号");
$("#form_type_1").val("1");
// $("#isShow").hide();//根据类型判断是否显示
$("#user_id").val(id);
	$.ajax({
			

url:'${pageContext.request.contextPath}/user/toEdit.action?id='+id,
			type: 'post',
			async : false,
			success:function(data){
				var obj = eval("(" + data + ")");
				$("#loginName").val(obj.loginName);
				$("#personName").val(obj.personName);
				$("#select_type option[value="+obj.wxGradeId+"]").prop("selected",true);
// 				  $("#select_type").find("option[value='"+data.type+"']").attr("selected",true);
				$("#select_isLock option[value='"+obj.isLock+"']").attr("selected", true);
				$("#doc-modal-1").modal('open');
			}
		});
}
//保存新增或更新
function save(){
	
	var type=$('#select_type option:selected').val();//选中的值
	$("#type").val(type);
	var flag = true;
		var type_=$("#form_type_1").val();
		var msg = "";
// 		if(flag)if($("#loginName").val() == ""){flag = false;msg = "请填写登录账号！";}
// 		if(flag)if(!/^[\d]+$/g.test(document.getElementById("loginName").value)){flag = false;msg = "只能输入數字！";}
		if(flag)if($("#personName").val() == ""){flag = false;msg = "请填写姓名！";}
// 		if(flag)if(!/^[\u4e00-\u9fa5]+$/gi.test(document.getElementById("personName").value)){flag = false;msg = "只能输入汉字！";}
// 		if(flag)if($("#phone").val() == ""){flag = false;msg = "请填写电话！";}
// 		if(flag)if(!/^[\d]+$/g.test(document.getElementById("phone").value)){flag = false;msg = "电话只能输入數字！";}
// 		if(flag)if(!/^\w+([-+.]\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*$/.test(document.getElementById("email").value)){flag = false;msg = "邮箱输入有误！";}
		if(flag){
		if(type_==0){
			
			$.ajax({
				url : '${pageContext.request.contextPath}/user/addUser.action',
				type: 'post',
				data:$('#form').serialize(),
				async : false,
				success:function(data){
				if(data.msg=="操作成功"){
				window.location.reload();
				}else{
				$("#msg_alert").html(data.msg);
				$('#my-alert').modal('open');
				}
				}
			});
			}else{
			$.ajax({
				url : '${pageContext.request.contextPath}/user/updateUser.action',
				type: 'post',
				data:$('#form').serialize(),
				async : false,
				success:function(data){
				if(data.msg=="操作成功"){
				window.location.reload();
				}else{
				$("#msg_alert").html(data.msg);
				$('#my-alert').modal('open');
				}
				}
			});
			
			}
		
		}else{
		$("#msg_alert").html(msg);
		$('#my-alert').modal('open');
		}
}

//删除
function del(id){
$("#del_id").val(id);
$("#my-confirm").modal('open');
}
function doDel(){
	var id=$("#del_id").val();
		$.ajax({
					url:'${pageContext.request.contextPath}/user/remove.action?ids='+id,
					type: 'post',
					async : false,
					success:function(data){
					my_alert(data.msg);
					window.location.reload();
					}
				});
	}
	
//批量删除
function removeAll(){
			{
	        var ids=[];
			var recordCount = grid_2_1_2.getCheckedRecords();
		    for(var i=0;i<grid_2_1_2.getCheckedRecords().length;i++){
		    	ids.push(recordCount[i]["id"]);
		    }
$("#my-confirm").modal('open');
$("#del_id").val(ids);
}
}

//条件查询
function query()
{	//传入实例化好的dt-grid 如grid_2_1_9和条件筛选的form的id
	//如果有其他固定的筛选条件，请在条件筛选的form中放入隐藏域
	//var state=$("#select_type_ option:selected").val();
	//$("#form_type").val(state);
	dtGridLoad(grid_2_1_2, "form-search"); 
}
//清空条件查询
function queryAll()
{	//传入实例化好的dt-grid 如grid_2_1_9和条件筛选的form的id
	//如果有其他固定的筛选条件，请在条件筛选的form中放入隐藏域
	$("#form_personName").val("");
	$("#form_loginName").val("");
	$("#form_phone").val("");
	//$("#form_type").val("");
	$("#select_type_").val("1");
	dtGridLoad(grid_2_1_2, "form-search"); 
}

//账号导出
function user_excel(){
	var params = {};
		$("#form-search input").each(function(){
     		var parametersName = $(this).attr("name");
     		var parametersValue = $(this).val();
     		params[parametersName] = parametersValue;
     	});
     	var str =JSON.stringify(params); 
	window.location.href="${pageContext.request.contextPath}/user/exportExcel.action?parameters="+str;
}

function LoadLevel(){
$.ajax({
					url:'${pageContext.request.contextPath}/user/LoadLevel.action',
					type: 'post',
					async : false,
					success:function(data){
					if (eval(data).length > 0) {
							var html = "";
							$.each(eval(data),function() {
													html += '<option value="'+this.id+'">'
															+ this.name
															+ '</option>';

											});
							$("#select_type").html(html);
						}
					}
				});
}
</script>


</html>
